﻿@model MvcCmsProjectTracker.ViewModels.ProjectMemberViewModel
<div id="members">
    @if (Model.AllUsers.Count > 0)
    {
        using (Ajax.BeginForm("UpdateMembers", "Project", new { id = Model.ProjectID }, new AjaxOptions { HttpMethod="POST", UpdateTargetId = "members", OnFailure = "handleFailure", OnSuccess = "styleControls" }))
        { 
        <div style="float: left">
            <b>Users</b><br />
            <select name="nonmembers" multiple="multiple" size="10" style="width: 150px">
                @foreach (var user in Model.AllUsers)
                {
                    var member = (from m in Model.Members
                                  where m.UserID == user.UserID
                                  select m).SingleOrDefault();
                    if (member == null)
                    {
                        @Html.Raw(string.Format("<option value=\"{0}\">{1}</option>", user.UserID, user.UserName))
                    }
                }
            </select>
        </div>
        <div style="float: left; padding: 50px 10px;">
            <input type="submit" value=">" name="add" />
            <br />
            <br />
            <input type="submit" value="<" name="remove" />
        </div>
        <div style="float: left">
            <b>Members</b><br />
            <select name="members" multiple="multiple" size="10" style="width: 150px">
                @foreach (var member in Model.Members)
                {
                    @Html.Raw(string.Format("<option value=\"{0}\">{1}</option>", member.User.UserID, member.User.UserName))
                }
            </select>
        </div>
        <div class="clear">
        </div>
        }
    }
    @Html.Partial("ControlsProjectTracker/Message", Model)
</div>
